﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using F1010DB.Common;
using F1010DB.Constant;
using F1010DB.Entity;
using F1010DB.CustomEntity.InitDanhMuc;
using System.Data;
using F1010DB.CustomEntity.Master;
using F1010DB.Enums;
namespace F1010DB.SecurityServices
{
    /// <summary>
    /// Khi loading data hay vao main form
    /// Load san sang cho may du lieu
    /// </summary>
    public class InitLoadDataServices : AbstractClassLoadData
    {

        public InitLoadDataServices()
        {
            initStringForBasical();
        }

        protected override string[] getSqlStringToSelect()
        {
            List<string> lstTable = new List<string>();

            lstTable.Add(TableNameList.TABLE_DANH_MUC_TINH_THANH);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_NGANH_HUONG_DAO);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_CAP_DON_VI);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_CHUYEN_DON_VI);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_LOAI_VAN_BAN);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_LOAI_CHI_PHI);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_LOAI_THU_CU);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_TRACH_VU);
            lstTable.Add(TableNameList.TABLE_DANH_MUC_CAP_HUAN_LUYEN);
            lstTable.Add(TableNameList.TABLE_COMMON_MASTER);

            return lstTable.ToArray();
            
        }

        private Dictionary<string, DataTable> getListDataTable()
        {
            return listGetData();
        }

        public void initGetListData()
        {
            Dictionary<string, DataTable> lst = getListDataTable();
            InitDisplayLoad.listDanhMuc = lst;
        }

        public void loadDataForMsg()
        {
            InitDisplayLoad.dictMessage = listMessages();
        }

        /// <summary>
        /// Init create list
        /// </summary>
        public void initMasterCommon()
        {
            DataTable dt = InitDisplayLoad.listDanhMuc[TableNameList.TABLE_COMMON_MASTER];
            InitDisplayLoad.commonMaster = new List<MasterCustomCommon>();

            foreach (DataRow dr in dt.Rows)
            {
                MasterCustomCommon masterCustomCommon = new MasterCustomCommon();

                masterCustomCommon.CommId = dr["COMM_ID"].ToString();
                masterCustomCommon.Key1 = dr["KEY_1"].ToString();
                masterCustomCommon.Key2 = dr["KEY_2"].ToString();
                masterCustomCommon.Key3 = dr["KEY_3"].ToString();
                masterCustomCommon.Key4 = dr["KEY_4"].ToString();
                masterCustomCommon.Key5 = dr["KEY_5"].ToString();
                masterCustomCommon.Value1 = dr["VALUE_1"].ToString();
                masterCustomCommon.MasterName = dr["MASTER_NAME"].ToString();
                masterCustomCommon.Required1 = dr["REQUIRED_1"].ToString().Equals("True") ? true : false;
                masterCustomCommon.calcualator = convertToCalc(dr["C1"].ToString());
                masterCustomCommon.equarator = convertToEquarator(dr["E1"].ToString());
                masterCustomCommon.logicalMaster = convertToLogical(dr["L1"].ToString());
                masterCustomCommon.typeMaster = convertToType(dr["T1"].ToString());
                masterCustomCommon.valueCalc = dr["VALUE_CALC"].ToString();
                InitDisplayLoad.commonMaster.Add(masterCustomCommon);
            }

        }

        /// <summary>
        /// Covert to Type Enum
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private EnumForMaster.TypeMaster convertToType(string value)
        {
            return ConvertToEnum<EnumForMaster.TypeMaster>.converToEnumFinal(value);
        }

        /// <summary>
        /// Convert to Logical
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private EnumForMaster.Logic convertToLogical(string value)
        {
            return value.Equals("NONE") ? EnumForMaster.Logic.NONE : ConvertToEnum<EnumForMaster.Logic>.converToEnumFinal(value);
        }

        /// <summary>
        /// Convert To Calc
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private EnumForMaster.Calc convertToCalc(string value)
        {
            return value.Equals("NONE") ? EnumForMaster.Calc.NONE : ConvertToEnum<EnumForMaster.Calc>.converToEnumFinal(value);
        }


        /// <summary>
        /// Convert to Equarator
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private EnumForMaster.Equarator convertToEquarator(string value)
        {
            return value.Equals("NONE") ? EnumForMaster.Equarator.NONE : ConvertToEnum<EnumForMaster.Equarator>.converToEnumFinal(value);
        }

        public Dictionary<string, string> defineNameLabelList()
        {
            Dictionary<string, string> lstDefine = new Dictionary<string, string>();

            lstDefine.Add(TableNameList.TABLE_DANH_MUC_CAP_DON_VI, "Danh mục cấp đơn vị");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_CAP_HUAN_LUYEN, "Danh mục loại huấn luyện trưởng");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_CHUYEN_DON_VI, "Danh mục loại chuyển đơn vị");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_LOAI_CHI_PHI, "Danhh mục loại chi phí");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_LOAI_THU_CU, "Danh mục loại thủ cụ");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_LOAI_VAN_BAN, "Danh mục loại văn bản");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_NGANH_HUONG_DAO, "Danh mục ngành hướng đạo");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_TINH_THANH, "Danh mục tỉnh thành");
            lstDefine.Add(TableNameList.TABLE_DANH_MUC_TRACH_VU, "Danh mục trách vụ");

            if (InitDisplayLoad.dicBasical != null || InitDisplayLoad.dicBasical.Count != 0)
            {
                foreach(string key in InitDisplayLoad.dicBasical.Keys)
                {
                    lstDefine.Add(key, InitDisplayLoad.dicBasical[key]);
                }
            }
            return lstDefine;

        }
    }


}
